import { defineComponent, onMounted, watch } from "vue";
import E from "wangeditor"; // npm 安装
const { $, BtnMenu, DropListMenu, PanelMenu, DropList, Panel, Tooltip } = E;
let editor: any;
export default defineComponent({
  props: {
    value: String,
  },
  emits: ["update:value"],
  setup(props, { emit }) {
    const init = () => {
      editor = new E("#editor");
      editor.config.uploadImgShowBase64 = true;
      editor.config.zIndex = 500;
      editor.config.onblur = (newHtml: any) => {
        emit("update:value", newHtml);
        console.log(newHtml, "skk");
      };
      editor.create();
    };
    watch(
      () => props.value,
      val => {
        if (editor) {
          editor.txt.html(val);
        }
      }
    );

    onMounted(() => {
      init();
    });
    return () => <div id="editor"></div>;
  },
});
